﻿using BaseClass;
using KG.ServiceLogic.Logic;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RelationDTO = KG.SystemService.RelationDTO;

namespace KG.API.Controllers
{
    /// <summary>
    /// 关系管理
    /// </summary>
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    public class relationController : Controller
    {
        private RelationLogic _relationLogic;
        public relationController(RelationLogic relationLogic)
        {
            _relationLogic = relationLogic;
        }

        /// <summary>
        /// 添加关系接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<RelationDTO.OutputId> add(RelationDTO.InputAdd req)
        {
            var result = new Response<RelationDTO.OutputId>();
            try
            {
                result.Result = _relationLogic.AddRelation(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 删除关系接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<RelationDTO.OutputId> delete(RelationDTO.InputDelete req)
        {
            var result = new Response<RelationDTO.OutputId>();
            try
            {
                result.Result = _relationLogic.DeleteRelation(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 条件检索关系接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<RelationDTO.OutputLoad> complexLoad([FromQuery] RelationDTO.InputComplexLoad req)
        {
            var result = new Response<RelationDTO.OutputLoad>();
            try
            {
                result.Result = _relationLogic.complexLoad(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 更新关系接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<RelationDTO.OutputId> update(RelationDTO.InputUpdate req)
        {
            var result = new Response<RelationDTO.OutputId>();
            try
            {
                result.Result = _relationLogic.UpdateRelation(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 查看关系信息接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<RelationDTO.OutputGet> get([FromQuery] RelationDTO.InputGet req)
        {
            var result = new Response<RelationDTO.OutputGet>();
            try
            {
                result.Result = _relationLogic.GetRelation(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 加载关系类型接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<RelationDTO.OutputTypeLoad> TypeLoad()
        {
            var result = new Response<RelationDTO.OutputTypeLoad>();
            try
            {
                result.Result = _relationLogic.TypeLoad();
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 加载关系信息接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<RelationDTO.OutputLoad> load([FromQuery] RelationDTO.InputLoad req)
        {
            var result = new Response<RelationDTO.OutputLoad>();
            try
            {
                result.Result = _relationLogic.load(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
    }
}
